<link rel="stylesheet" href="../css/reset.css"/>
<link rel="stylesheet" href="../css/addarea.css"/>
<script type="text/javascript"></script>
<div class="add" ng-controller="addareactrl">
    <div><p>添加新地址</p></div>
    <ul>
        <li class="clearfix">
        	
            <span class="l">*</span><span class="l">收货人姓名:</span><div class=" l"><input class="firstname" type="text" /></div>
        </li>
        <li class="clearfix">
            <span class="l">*</span>
            <span class="l">所在地区:</span>
            <div class="area1 l">
                <div class="privincehead">请选择</div>
                <ul class="privince"></ul>
                <img src="../img/downtrigle.png" alt=""/>
            </div>
            <div class="area2 l">
                <div class="cityhead">请选择</div>
                <ul class="city"></ul>
                <img src="../img/downtrigle.png" alt=""/>
            </div>
            <div class="area3 l">
                <div class="countryhead">请选择</div>
                <ul class="country"></ul>
                <img src="../img/downtrigle.png" alt=""/>
            </div>
        </li>
        <li class="clearfix">
            <span class="l">*</span><span class="l">详细地址:</span><div class="l"><input class="add_a" type="text"/></div>
        </li>
        <li class="clearfix">
            <span class="l">*</span><span class="l">联系电话:</span><div class="l"><input class="add_ph" type="text"/></div><span class="l">或固定电话:</span><div class="l"><input class="fix_first" type="text"/></div><span class="l">-</span><div class="l"><input  class="fix_last" type="text"/></div>
        </li>
    </ul>
    <span class="common"></span><span>设置为常用地址</span>
    <div class="save">保存</div>
</div>
<script type="text/javascript">
    var na,p,c,co;
    var arr=[];
    var arr1 = [];
    $('.firstname').bind('input propertychange', function() {
        na = $(this).val();

    });
    $(".privincehead").bind('DOMNodeInserted', function(e) {
        var p = $(e.target).html();
        arr.push(p);
    });
    $(".cityhead").bind('DOMNodeInserted', function(e) {
        var c = $(e.target).html();
        arr.push(c);
    });
    $(".countryhead").bind('DOMNodeInserted', function(e) {
        var co = $(e.target).html();
        arr.push(co);
    });
    $('.add_a').bind('input propertychange', function() {
        adda = $(this).val();

    });
    $('.add_ph').bind('input propertychange', function() {
        addph = $(this).val();

    });

    $('.save').click(function(){
        var fixph = $('.fix_first').val();
        var fixone = $('.fix_last').val();
        arr1.push(fixph);
        arr1.push(fixone);
        
        var pc = arr.join('');
        var fixphone = arr1.join('-');
        
        if($('.firstname').val()==''){
        	   alert('请输入姓名')
        }else if($('.privincehead').html()=='请选择'||$('.cityhead').html()=='请选择'||$('.countryhead').html()=='请选择') {
        		alert('请选择地区')
        } else if ($('.add_a').val()==''){
        		alert('请输入详细地址')
        }else if(!(/^1(3|4|5|7|8)\d{9}$/.test($('.add_ph').val()) || /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/.test(fixphone))){
                alert('请输入正确的手机号或者固定电话');
        }else{
	        	var obj = {};
	        obj.name = na;
	        obj.area = pc;
	        obj.detail = adda;
	        obj.phone = addph;
	        obj.fixphone = fixphone;
			$.post('../php/database.php',obj,function(data){
              if(data=='插入成功'){
                 alert('插入成功')
              }else{
                  alert('请输入正确的手机号或者密码')
              }
          })
       }
    })
</script>